from gameServer  import gameServer
from eventServer import eventServer
from collectCube import CollectCube
from shrapnel    import Shrapnel
from vec2        import Vec2
import math
from soundServer import sound

class ClusterBomb(CollectCube):
    
    def __init__(self):
        CollectCube.__init__(self)
        self.setVar("texture", "clusterBomb")
        self.bomb_parts  = 7.0
        self.bomb_vel    = 40
        self.bomb_killed = {}
        
    def use(self, cmd, args):
        if(args["bin"]):
            p = self.getVar("itemPlayer")
            v = p.getVar("pos")
            eventServer.pull("itemCollected", {"player":p.getVar("player"), "collected":None})
            
            for i in range(self.bomb_parts):
                pos = p.getVar("pos")
                rot = i * (math.pi/self.bomb_parts)
                px  = 1 * math.cos(rot)
                py  = 1 * math.sin(rot)
                vx  = self.bomb_vel * math.cos(rot)
                vy  = self.bomb_vel * math.sin(rot)
                s = gameServer.addObject(gameServer.makeObjectName("Shrapnel_"), Shrapnel(p.getVar("player"), self, Vec2(pos.x + px, pos.y + py), Vec2(vx, vy)))
            sound.play("clusterBomb_explode")
                
    def report(self, fromPlayer, toPlayer):
        if(not(self.bomb_killed.has_key(toPlayer))):
            self.bomb_killed[toPlayer] = True
            eventServer.pull('playerStomp',{'fromPlayer':fromPlayer,'toPlayer':toPlayer})
            sound.play("clusterBomb_kill")